package arena;

import menu.PanelMain;

import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.renderer.pass.BasicPassManager;
import com.jme.renderer.pass.RenderPass;
import com.jme.renderer.pass.ShadowedRenderPass;
import com.jme.scene.Node;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;

public class ArenaRPS extends GameState{
	public Renderer 				renderer = DisplaySystem.getDisplaySystem().getRenderer();
	public ShadowedRenderPass 		shadowpass = new ShadowedRenderPass();;
	public BasicPassManager 		pManager = new BasicPassManager();;
	public RenderPass 				rPass = new RenderPass();;
	public static ArenaRPS			arenaRPS;
	private ArenaGS					gs;
	
	public static ArenaRPS getInstance()
	{
		if(arenaRPS==null)
			arenaRPS = new ArenaRPS("RPS");
		return arenaRPS;
	}
	
	public void setGS(ArenaGS gs)
	{
		this.gs=gs;
	}
	
	public void initGame()
	{
		
	}
	
	private ArenaRPS(String name)
	{
		setName(name);
		gs=(ArenaGS) GameStateManager.getInstance().getChild("GS");
		Node rootNode  = gs.getRootNode();
		Node occluders = gs.getOccludersNode();
		
		shadowpass.add(rootNode);
		shadowpass.addOccluder(occluders);
		shadowpass.setRenderVolume(false);
		shadowpass.setShadowColor(new ColorRGBA(0.0f, 0.0f, 0.0f, 0.0f));
		shadowpass.setLightingMethod(ShadowedRenderPass.LightingMethod.Modulative);
		shadowpass.setRenderShadows(true);

		rPass.add(gs.getFpsNode());
		if(PanelMain.settings.playerEffects==0) pManager.add(shadowpass);
		pManager.add(rPass);
	}
	
	@Override
	public void cleanup() {}

	@Override
	public void render(float tpf)
	{
		try{
			pManager.renderPasses(renderer);
		}
		catch (IndexOutOfBoundsException e)
		{ e.printStackTrace();}	
		catch (RuntimeException e)
		{
			System.out.println("RENDERPASS FRAMEBUFFER FAIL");
		}
	}

	@Override
	public void update(float tpf)
	{ pManager.updatePasses(tpf);}

}
